const dayjs = require('dayjs');
const { Controller } = require('varal');

class WithdrawalController extends Controller {
	async index(app) {
		const { fullname, phone, page = 1, page_size = 20 } = app.fields;

		const serv = app.service('WithdrawalService');
		const { data, total } = await serv.get({
			fullname, phone
		}, page, page_size);

		this.app.json({
			err_code: 0,
			data: {
				data: data.map((d) => {
					const { amount, create_time } = d.dataValues;
					d.dataValues.create_time = dayjs(create_time).format('YYYY-MM-DD HH:mm:ss');

					//结算金额
					//d.dataValues.settlement_amount = 0;

					return d.dataValues;
				}),
				total
			}
		})
	}

	async save(app) {
		const { id, status, reason } = app.fields;
		const serv = app.service('WithdrawalService');
		await serv.save({
			id,
			status,
			reason
		});

		this.app.json({
			err_code: 0
		})
	}
}


exports = module.exports = WithdrawalController;
